﻿#region 程序集引用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
#endregion

#region 版权注释
/*===========================================================================
// Copyright (C) 2017 seabay.cn，并保留所有 
// 作者：吴岸标 QQ:405403610
// 创建日期：2017-01-18
// 功能描述： 文件上传基类 Controller
===========================================================================*/
#endregion

namespace Zhang
{
    namespace AdminPage
    {
        /// <summary>
        /// 基类 Controller
        /// </summary>
        public class FileUploadController : System.Web.Mvc.Controller
        {
            // 是否通过身份验证
            private bool _isValid = false;
            // 用户标识
            private string _tag = string.Empty;
            /// <summary>
            /// 图片文件内容类型列表，防止其它文件改后缀名上传
            /// </summary>
            protected const string ImageContentTypeList = "|image/x-icon|image/png|image/gif|image/jpeg|image/x-png|image/bmp|image/pjpeg|IMAGE/X-ICON|IMAGE/PNG|IMAGE/GIF|IMAGE/JPEG|IMAGE/X-PNG|IMAGE/BMP|IMAGE/PJPEG|";
            /// <summary>
            /// 当前页面功能名称
            /// </summary>
            protected string ModelName { get; set; }
            /// <summary>
            /// 是否通过身份验证
            /// </summary>
            protected bool IsValidated
            {
                get
                {
                    return _isValid;
                }
            }

            /// <summary>
            /// 用户标识
            /// </summary>
            protected string Tag
            {
                get
                {
                    return _tag;
                }
            }

            protected override void OnAuthorization(AuthorizationContext filterContext)
            {
                base.OnAuthorization(filterContext);

                _tag = Request["tag"];
            }

           

            /// <summary>
            /// 判断文件类型是否允许上传
            /// </summary>
            /// <param name="fileExtention">文件扩展类型</param>
            /// <param name="imgAllowType">配置值</param>
            /// <returns></returns>
            protected bool IsAllowExtension(string fileExtention, string[] imgAllowType)
            {
                bool isTrue;

                isTrue = false;
                fileExtention = fileExtention.Trim().ToLower().Replace(".", "");

                foreach (string item in imgAllowType)
                {
                    if (item.Trim() == fileExtention)
                    {
                        isTrue = true;
                        break;
                    }
                }

                return isTrue;
            }

            ///// <summary>
            ///// 页面级错误处理
            ///// </summary>
            ///// <param name="sender"></param>
            ///// <param name="e"></param>
            //protected override void OnException(ExceptionContext filterContext)
            //{
            //    Exception ex = filterContext.Exception;
            //    LogHelper.Write(ModelName, "【" + ex.Message + "】" + ex.ToString());//统一到LogHelper
            //    //IDALFactory.CommonAccess.Log().ExpInsert(ModelName, "【" + ex.Message + "】" + ex.ToString());
            //}

            ///// <summary>
            ///// 添加异常日志
            ///// </summary>
            ///// <param name="ex"></param>
            //protected void WriteExceptionLog(Exception ex)
            //{
            //    LogHelper.Write(ModelName, "【" + ex.Message + "】" + ex.ToString());//统一到LogHelper
            //    //IDALFactory.CommonAccess.Log().ExpInsert(ModelName, "【" + ex.Message + "】" + ex.ToString());
            //}
        }
    }
}
